from selenium import webdriver
import time
from selenium.webdriver.common.by import By


class TestCase:
    def __init__(self):
        # 初始化对象,这里要初始化浏览器对象
        self.driver = webdriver.Chrome("C:\Program Files\Google\Chrome\Application\chromedriver.exe")
        # 访问百度
        self.driver.get('https://www.baidu.com')

    def baidu_serch(self):
        # 定位搜索框,并且输入文本
        self.driver.find_element(By.ID, 'kw').send_keys('python自动化测试')  # 链式操作
        # 点击百度一下的按钮
        self.driver.find_element(By.ID, 'su').click()
        time.sleep(3)
        # 获取页面标题做判断
        if 'python' in self.driver.title:
            print('找到了')
        else:
            print('没找到')

    # 关闭浏览器
    def quit(self, seconds=3):
        time.sleep(seconds)
        self.driver.quit()


case = TestCase()
case.baidu_serch()
case.quit()
